package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
 * 练习:
 * 使用Student的无参构造器和全参构造器分别实例化
 */

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Student student = new Student("王五",18,'女');
        System.out.println(student);

        Class cls = Class.forName("reflect.Student");

        Constructor c = cls.getConstructor(String.class,int.class,char.class);

        Object obj = c.newInstance("赵六",12,'男');

        System.out.println(obj);

        Constructor c1 = cls.getConstructor();
        Object obj2 = c1.newInstance();
        System.out.println(obj2);




    }
}
